import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(Vuex)
Vue.use(VueAxios, axios)

export default new Vuex.Store({
    state: {
        devMode: false,
        tokenStr: '',
        isAdmin: false,
        routerData: {
            //routerSequance: ['admin'],
            //routerSequance: ['input', 'belbininit', 'belbinmain', 'belbinresult', 'holland', 'hollandmain', 'hollandinput', 'hollandfinal', 'end'],
            routerSequance: ['input', 'belbininit', 'belbinmain', 'holland', 'hollandmain', 'hollandinput', 'end'],
            routerPointer: 0,
            nextView: null
        },
        userInfo: null,
        baseData: null,
        scoreData: [],
        belbinScore: null,
        description: [],
        hollandData: {
            baseData: null, //brief(parts,types), contents()
            scoreData: {
                values: [],
                inputs: []
            },
            description: []
        }
    },
    mutations: {
        verifyAdmin(state, payload) {
            state.tokenStr = payload;
            state.isAdmin = true;
        },
        initialize(state, responseData) {
            state.baseData = responseData;
            state.scoreData = [];
            for (let i = 0; i < responseData.length; i++) {
                state.scoreData.push(null);
            }
        },
        initializeHolland(state, responseData) {
            state.hollandData.baseData = responseData;
            window.console.log(state.hollandData)
        },
        setValueHolland(state, payload) {
            if (payload.part == "values") {
                state.hollandData.scoreData.values = payload.content;
            } else if (payload.part == "inputs") {
                state.hollandData.scoreData.inputs = payload.content;
            }
        },
        setUserInfo(state, payload) {
            state.userInfo = payload;

        },
        setValueBelbin(state, payload) {
            state.belbinScore = payload;
        },
        setValue(state, payload) {
            state.scoreData[payload.index] = payload.value;
            //window.console.log(payload);
        },
        initDescription(state, responseData) {
            state.description = responseData;
        },
        initDescriptionHolland(state, responseData) {
            state.hollandData.description = responseData;
        },
        routerNext(state) {
            let i = state.routerData.routerPointer + 1;
            state.routerData.routerPointer = i;
            state.routerData.nextView = state.routerData.routerSequance[i];
        },
        routerInit(state) {
            state.routerData.routerPointer = 0;
            state.routerData.nextView = state.routerData.routerSequance[0];
        }

    },
    actions: {
        initialize(context) {
            context.commit('routerInit');
            axios.get('belbin.json').then(response => {
                context.commit('initialize', response.data)
            });
            axios.get("description.json").then(response => {
                context.commit('initDescription', response.data)
            });
            axios.get('holland.json').then(response => {
                context.commit('initializeHolland', response.data)
            });
            axios.get("description_holland.json").then(response => {
                context.commit('initDescriptionHolland', response.data)
            });
        }
    }
})